﻿//1.类型模式
object obj="Hello World";
switch (obj)
{
    case int i :
        Console.WriteLine($"整数：{i}") ;
        break ;
    case string s :
        Console.WriteLine($"字符串：{s}") ;
        break ;
    case null :
        Console.WriteLine("空值") ;
        break ;
    default : 
        Console.WriteLine("未知类型") ;
        break ;
}

//2.变量模式
object obj1= 24 ;
switch(obj1)
{
    case var x when x is int && (int)x > 30 :
        Console.WriteLine("大于30的整数") ;
        break ;
    default :
        Console.WriteLine("其他情况");
        break ;
}

//3.范围模式
int score = 85;
switch(score)
{
    case int s when s >= 90:
        Console.WriteLine("优秀");
        break;
    case int s when s >= 80 && s <= 90:
        Console.WriteLine("良好");
        break;
    default:
        Console.WriteLine("其他");
        break;
}

//4.属性模式
/*Person p=new Person{Name="Bob",Age=25,Sex='N'}; 
string des=p switch{
    {Age:<18}=>"未成年人",
    {Age:>=18 and <60}=>"成年人",
    {Age:>60}=>"老年人",
    _=>"未知"
};
Console.WriteLine (des) ;
public class Person
{
    public string Name{get;set;}
    public int Age {get;set;}
    public char Sex{get;set;}
}*/

// 5.循环
int count=0;
while(count <3){
    Console.WriteLine("while!");
    count++;
}
int count2=0;
do{
    Console.WriteLine("do...while");
    count2++;
}while(count<3);